package com.gwclh.personnel.controller;

import cn.hutool.core.util.StrUtil;
import com.gwclh.personnel.domain.PageDomain;

import javax.servlet.http.HttpServletRequest;

public abstract class BaseController{

    /**
     * 设置请求分页数据封装
     * 前端格式为{pageNum:1,pageSize:10,sortColumn:"create_time",isAsc:"asc/desc"}
     */
    protected PageDomain getPageParams(HttpServletRequest request)
    {

        String pageNum = request.getParameter("pageNum");
        if (StrUtil.isEmpty(pageNum)) {
            pageNum = "1";
        }
        String pageSize = request.getParameter("pageSize");
        if (StrUtil.isEmpty(pageSize)) {
            pageSize = "10";
        }
        String sortColumn = request.getParameter("sortColumn");
        if(StrUtil.isEmpty(sortColumn)){
            sortColumn = "create_time";
        }
        String isAsc = request.getParameter("isAsc");
        if(StrUtil.isEmpty(isAsc)){
            // 默认升序
            isAsc = "asc";
        }
        PageDomain pageDomain = new PageDomain();
        pageDomain.setPageNum(Integer.valueOf(pageNum));
        pageDomain.setPageSize(Integer.valueOf(pageSize));
        pageDomain.setSortColumn(sortColumn);
        pageDomain.setIsAsc(!isAsc.equals("desc"));
        return  pageDomain;
    }

}